package com.wjboot;

import com.tangzc.mpe.autotable.EnableAutoTable;
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import com.wjboot.common.mybatis.annotation.EnableDynamicDataSource;
import lombok.SneakyThrows;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;

/**
 * @author 周振林
 */
// @EnableAutoTable启用自动生成数据库表功能，此处简化了A.CTable的复杂配置，均采用默认配置
// @EnableAutoTable.activeProfile为非必填值，属性值为空时默认激活自动建表能力。
// activeProfile属性值会参考spring-boot的配置项“spring.profiles.active”的值，两者的属性值取交集后，存在共同值则开启自动建表
// 例如：spring.profiles.active=dev,test，activeProfile={"local",
// "dev"}，他们都有dev，则启动自动建表，本身表达的含义是，spring激活了dev和test环境配置，自动建表生效在local和dev配置下
// 假设只有dev、test两个环境激活自动建表操作，配置如下。
@EnableAutoTable
// @EnableAutoTable(activeProfile = {"dev", "test"})
@SpringBootApplication
@EnableEncryptableProperties
@EnableCaching
@EnableDynamicDataSource
public class WjBootApplication {

    private static Logger logger = LoggerFactory.getLogger(WjBootApplication.class);

    @SneakyThrows
    public static void main(String[] args) {

//        SpringApplication.run(ChaosApplication.class, args);
        SpringApplication app = new SpringApplication(WjBootApplication.class);
        ConfigurableApplicationContext application = app.run(args);

        Environment env = application.getEnvironment();
        logger.info("\n----------------------------------------------------------\n\t" +
                        "Application '{}' is running! Access URLs:\n\t" +
                        "Local: \t\thttp://localhost:{}\n\t" +
                        "External: \thttp://{}:{}\n\t" +
                        "Doc: \thttp://{}:{}/doc.html\n" +
                        "----------------------------------------------------------",
                env.getProperty("spring.application.name"),
                env.getProperty("server.port"),
                InetAddress.getLocalHost().getHostAddress(),
                env.getProperty("server.port"),
                InetAddress.getLocalHost().getHostAddress(),
                env.getProperty("server.port"));
    }

}
